﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Collections;


namespace ObligatorioBD
{
    public partial class FormSelector : Form
    {
        public FormSelector()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Muestra un dialogo de selección de archivo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                txtFilePath.Text = openFileDialog.FileName;
            }
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            FileReader f = new FileReader(this.txtFilePath.Text);
            string contenidoXml = f.Download();
            XMLData.XMLData x = new XMLData.XMLData(contenidoXml);
            Logic.MERInterpreter mer = new Logic.MERInterpreter(contenidoXml);
            mer.Interpret();
            mer.PersistMer();
            this.Cursor = Cursors.Default;
            MessageBox.Show("Mer cargado con éxito!");
            this.Close();
        }
        private void FormSelector_Load(object sender, EventArgs e)
        {
            toolTip.SetToolTip(btnLoad, "Lee los datos del archivo seleccionado \ry los carga para inicializar el programa.");
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void connectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DatabaseInterface.ConfigureConnection c = new DatabaseInterface.ConfigureConnection();
            c.ShowDialog();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAbout f = new frmAbout();
            f.ShowDialog();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            Logic.DatabaseCreator dc = new Logic.DatabaseCreator(new DatabaseInterface.Connection(), "pru12");
            dc.NewTable("Prueba");
            dc.AddColumn("IdPrueba",Microsoft.SqlServer.Management.Smo.DataType.Int,false,true);
            dc.AddColumn("desc",Microsoft.SqlServer.Management.Smo.DataType.VarChar(20),false,true);
            dc.CrateTable();
            //frmTesting f = new frmTesting();
            //if (rdbCurrentCnx.Checked)
            //{
            //    f = new frmTesting();
            //    f.Show();
            //}
            //if (rdbNewCnx.Checked)
            //{
            //    frmDatabaseName dName = new frmDatabaseName();
            //    DialogResult result = dName.ShowDialog();
            //    if (result == System.Windows.Forms.DialogResult.OK)
            //    {
            //        f.NewDataBase = true;
            //        f.DatabaseName = dName.DatabaseName;
            //        f.Show();
            //    }
            //}
        }        
    }
}